<template>
  <div class="customerOverview-container">
    <div class="customerOverview-page">

      <el-card>
        <div>
          <el-button size="small" type="primary" @click="showpop()">新增售后</el-button>
        </div>
        <el-table :data="list" border v-loading="listLoading" style="width: 100%; margin: 20px 0">
          <el-table-column
            label="合同号"
            align="center"
            min-width="150">
            <template slot-scope="scope">
                {{scope.row.orderSn}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="申请时间"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.applyTime}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="售后原因"
            min-width="150">
            <template slot-scope="scope">
               {{scope.row.applyReason}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="售后凭证"
            min-width="150">
            <template slot-scope="scope">
                <img :src="item"  v-for="item  in scope.row.applyCertificate" style="width:50px;height:50px;object-fit: contain;cursor: pointer;margin-right:5px;" @click="fullImg(item)"/>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="状态"
            min-width="150">
            <template slot-scope="scope">
                {{scope.row.applyStateStr}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="处理结果"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.handleResult}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="处理凭证"
            min-width="150">
            <template slot-scope="scope">
              <img :src="item"  v-for="item  in scope.row.handleCertificate" style="width:50px;height:50px;object-fit: contain;cursor: pointer;margin-right:5px;" @click="fullImg(item)"/>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="申请人"
            min-width="150">
            <template slot-scope="scope">
                {{scope.row.applyUserName}}
            </template>
          </el-table-column>

          <el-table-column
            fixed="right"
            align="center"
            label="操作"
            min-width="150">
            <template slot-scope="scope">
                 <el-button type="text" v-if="scope.row.applyState == 0 && scope.row.isCanHandle == 1 " @click="showCl(scope.row)">处理</el-button>
                 <el-button type="text" v-if=" scope.row.applyState != 10 && scope.row.isCanHandle == 1" @click="showCancel(scope.row)">取消</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-container">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total, sizes,prev, pager, next,jumper"
            :page-size="listQuery.pageSize"
            :page-sizes="[10,15,20]"
            :current-page.sync="listQuery.pageNum"
            :total="count">
          </el-pagination>
        </div>
      </el-card>
    </div>
    <addSh ref="addSh" @getList="getList"></addSh>
    <clSh ref="clSh" @getList="getList"></clSh>
    <!--放大图片-->
    <el-dialog
      :visible.sync="dialogVisible4"
      width="800px">
      <img :src="fullSrc" style="width:100%;"/>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import {formatDate} from '@/utils/date';
import store from '@/store'
import {getCustomerOption, addRelatio, delRelation,} from '@/api/partner'
import {developAfterSale,developAfterSaleCancel,customerNewBaseInfo} from '@/api/company'
import addSh from './addSh'
import clSh from './clSh'
const defaultListQuery={
  tab:'all',
  customerId:'',
  "pageNum" : 1,
  "pageSize" : 10
};
export default {
  name: "customerSycl",
  data(){
    return{
      roles:store.getters.roles ? store.getters.roles : [],
      list:[],
      listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
      count: 0,
      listLoading: false,
      dialogVisible4:false,
      fullSrc:'',
    }
  },
  components : {
    addSh,clSh
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),

  },
  created() {

  },
  filters: {

  },
  methods:{
    showCl(item){
      this.$refs.clSh.showPop(item)
    },
    showCancel(item){
      this.$confirm('是否确认取消?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        developAfterSaleCancel({applyId:item.applyId}).then(()=>{
          this.$message({
            type: 'success',
            message: '取消成功!'
          });
          this.getList()
        })
      }).catch(() => {

      });
    },
    fullImg(src){
      this.dialogVisible4 = true;
      this.fullSrc = src;
    },
    //获取客户基本信息
    getInfo(){
      customerNewBaseInfo({customerId:this.listQuery.customerId}).then((res)=>{
        this.info = res
      })
    },

    init(customerId){
      this.listQuery.customerId = customerId;
      this.getList();
      this.getInfo()
    },
    handleSizeChange(val){
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val){
      this.listQuery.pageNum = val;
      this.getList();
    },

    handleSearchList(){
      this.listQuery.pageNum = 1;
      this.getList();
    },
    //获取列表
    getList() {
      this.listLoading = true;
      developAfterSale(this.listQuery).then(response => {
        this.list = response.list;
        this.count = response.count;
        this.listLoading = false;
      }).catch(()=>{
        this.listLoading = false;
      });
    },
    showpop(){
      let data = {
        customerId:this.listQuery.customerId,
        customerName:this.info.customerName
      }
      this.$refs.addSh.showPop(data)
    }
  }
}
</script>

<style lang="scss">


</style>
